set more off

*** read data ***

use "reassessments", clear

merge 1:1 swis_code year using "switchers"
keep if _m == 3
drop _m

merge 1:1 muni_name county_name year using "census demographics"
drop _m

merge m:m muni_name county_name year using "finances clean"
drop _m

merge 1:1 muni_name county_name year using "employment"
drop _m

drop if mi(swis_code)
keep if year > 1986 & year < 2012

*** recode for interpretation ***

gen elected = 1-D
replace reass = reass * 100

*** controls ***

#delimit;

local X1
	lpopulation 
	lmedianincome 
	pct65plus 
	pctwhite 
	pctunemployed 
	pctrenter 
	pctagricuture
	;

#delimit cr

local X2 ltotalrevenue pctptax surpluspcp totalftequivalent

*** run the regressions ***

eststo clear

gen salience = pct65plus1990
su salience
replace salience = (salience - r(min)) / (r(max) - r(min))
gen electedXsalience = elected*salience

eststo: xi: areg reass elected electedXsalience i.year, a(swis_code) cl(swis_code)
eststo: xi: areg reass elected electedXsalience i.year `X1', a(swis_code) cl(swis_code)
eststo: xi: areg reass elected electedXsalience i.year `X1' `X2', a(swis_code) cl(swis_code)
test elected+electedXsalience=0

label variable elected "Elected assessor"
label variable salience "Percent 65 and older"
label variable electedXsalience "Elected $\times$ percent 65 and older"

#delimit;

esttab
	using "table 3.tex"
	,
		replace
		cells(b(fmt(2) star) se(par))
		eqlabels(none)
		nomtitles
		collabels(none)
		gap
		keep(elected electedXsalience)
		label
		mlabels(none)
		nonotes
		booktabs
		width(\hsize)
		indicate("Demographic controls = lpopulation" "Fiscal controls = ltotalrevenue")
		stats(

			N
			,
				label(

					"Observations"
						
				)
				fmt(%20.0fc)
		)
	
		;
	
#delimit cr

shell "tabler.sh" "table 3.tex" "Reassessment" "Town"
